package com.motu.monstercity.server.game.logic;

import com.motu.monstercity.server.game.commondata.bag.Box;
import com.motu.monstercity.server.game.commondata.bag.Item;
import com.motu.monstercity.server.game.userdata.UserChip;
import com.motu.monstercity.server.game.userdata.UserItem;
import com.motu.vertx.module.utility.model.EntityManager;
import com.motu.vertx.module.utility.model.Model;

import java.util.ArrayList;
import java.util.List;

public class BagUserData extends BagBaseData {
    public static UserItem getUseritem(long userId, int itemId) {
        return (UserItem) EntityManager.getEntity(UserItem.class, userId, itemId);
    }

    public static UserChip getUserChip(long userId, int chipId) {
        return (UserChip) EntityManager.getEntity(UserChip.class, userId, chipId);
    }

    // 获取useritem列表 useritem表存的有item配置的道具，和box表配置的宝箱
    public static List<UserItem> getUserItemList(long userId) {
        List<UserItem> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserItem.class, userId)) {
            UserItem entity = (UserItem) model;
            Item item = getItem(entity.getItemId());
            Box box = getBox(entity.getItemId());
            if (item == null && box == null) {
                entity.delete();//item表策划注释掉的道具，删除
            } else {
                if (entity.getNum() <= 0) {
                    continue;
                }
                list.add(entity);
            }
        }
        return list;
    }

    public static List<UserChip> getUserChipList(long userId) {
        List<UserChip> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserChip.class, userId)) {
            UserChip entity = (UserChip) model;
            if (entity.getNum() <= 0) {
                continue;
            }
            list.add(entity);
        }
        return list;
    }
}
